package org.jeecg.modules.demo.zhibiaobiao.controller;

import java.io.File;
import java.io.FileInputStream;
import java.util.*;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.ss.usermodel.*;

import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.demo.jieshouzhibiaodaibanbiao.entity.Jieshouzhibiaodaibanbiao;
import org.jeecg.modules.demo.jieshouzhibiaodaibanbiao.service.IJieshouzhibiaodaibanbiaoService;
import org.jeecg.modules.demo.zhibiaobiao.dto.ZhibiaobiaoDto;
import org.jeecg.modules.demo.zhibiaobiao.entity.Zhibiaobiao;
import org.jeecg.modules.demo.zhibiaobiao.entity.Zhibiaoleixing;
import org.jeecg.modules.demo.zhibiaobiao.mapper.ZhibiaoleixingMapper;
import org.jeecg.modules.demo.zhibiaobiao.service.IZhibiaobiaoService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.modules.system.entity.SysDepart;
import org.jeecg.modules.system.entity.SysUserRole;
import org.jeecg.modules.system.mapper.SysDepartMapper;
import org.jeecg.modules.system.service.ISysUserRoleService;
import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.apache.shiro.authz.annotation.RequiresPermissions;
 /**
 * @Description: 制定年度关键指标
 * @Author: jeecg-boot
 * @Date:   2025-09-24
 * @Version: V1.0
 */
@Tag(name="制定年度关键指标")
@RestController
@RequestMapping("/zhibiaobiao/zhibiaobiao")
@Slf4j
public class ZhibiaobiaoController extends JeecgController<Zhibiaobiao, IZhibiaobiaoService> {
	@Autowired
	private IZhibiaobiaoService zhibiaobiaoService;
	@Autowired
	private SysDepartMapper sysDepartMapper;
	@Autowired
	private ZhibiaoleixingMapper zhibiaoleixingMapper;
	@Autowired
	private IJieshouzhibiaodaibanbiaoService jieshouzhibiaodaibanbiaoService;
	@Autowired
	private ISysUserRoleService sysUserRoleService;
	/**
	 * 分页列表查询
	 *
	 * @param zhibiaobiao
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "制定年度关键指标-分页列表查询")
//	@Operation(summary="制定年度关键指标-分页列表查询")
//	@GetMapping(value = "/list")
//	public Result<IPage<Zhibiaobiao>> queryPageList(Zhibiaobiao zhibiaobiao,
//								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
//								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
//								   HttpServletRequest req) {
//
//
//        QueryWrapper<Zhibiaobiao> queryWrapper = QueryGenerator.initQueryWrapper(zhibiaobiao, req.getParameterMap());
//		Page<Zhibiaobiao> page = new Page<Zhibiaobiao>(pageNo, pageSize);
//		IPage<Zhibiaobiao> pageList = zhibiaobiaoService.page(page, queryWrapper);
//		return Result.OK(pageList);
//	}

	 @GetMapping(value="/list")
	 public Result<IPage<ZhibiaobiaoDto>> list(Zhibiaobiao zhibiaobiao,
	 									@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
										@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
										HttpServletRequest  req){
		 //获取登录用户的id，只展示对应部门的数据
		 LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
		 String departId = loginUser.getDepartIds();
		 //显示全部的数据，再根据操作的情况，为驳回情况添加数据（来自接收表的驳回字段，传入配合部门id），显示驳回的部门名称
		 Page<Zhibiaobiao> page = new Page<Zhibiaobiao>(pageNo, pageSize);
		 QueryWrapper<Zhibiaobiao> queryWrapper = new QueryWrapper();
		 queryWrapper.eq("zerenbumen",departId);
		 IPage<Zhibiaobiao> pageList = zhibiaobiaoService.page(page, queryWrapper);
		 List<Zhibiaobiao> list = pageList.getRecords();
		 IPage<ZhibiaobiaoDto> pageList1 = new Page<>();
		 List<ZhibiaobiaoDto> dto = new ArrayList<>();
		 for(int i = 0;i<list.size();i++){
			 ZhibiaobiaoDto zhibiaobiaoDto = new ZhibiaobiaoDto();
			 //copyProperties方法：将需要的旧对象的属性值复制给新对象中
			 BeanUtils.copyProperties(list.get(i),zhibiaobiaoDto);

			 String id = list.get(i).getId();
			 QueryWrapper<Jieshouzhibiaodaibanbiao> qw = new QueryWrapper();
			 qw.eq("zhibiaoid",id);
			 List<Jieshouzhibiaodaibanbiao> list1 = jieshouzhibiaodaibanbiaoService.list(qw);
			 String zhuangtai = "";
			 for(int j=0;j<list1.size();j++){
				 if(list1.get(j).getZhuangtai().equals("已驳回")){
					 zhuangtai = zhuangtai + list1.get(j).getPeihebumen() + ",";
				 }
			 }
			 //去除最后一个字符
			 if(zhuangtai.length()>0){
				 zhuangtai = zhuangtai.substring(0,zhuangtai.length()-1);
			 }
			 zhibiaobiaoDto.setBohuiqingkuang(zhuangtai);
			 dto.add(zhibiaobiaoDto);
		 }
		 pageList1.setRecords(dto);
		 return Result.OK(pageList1);

	 }

	 //年度关键指标列表
	 @GetMapping(value="/liebiaoList")
	 public Result<IPage<ZhibiaobiaoDto>> liebiaoList(Zhibiaobiao zhibiaobiao,
													  @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
													  @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
													  HttpServletRequest  req){
		 //获取登录用户的部门id，用于查询自己主管和配合的项目
		 LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
		 String departId = loginUser.getDepartIds();
		 //根据获得的部门id。去指标表根据责任部门字段查询自己主管的项目，给主管/配合赋“我主管的”字段

		 Page<Zhibiaobiao> page1 = new Page<Zhibiaobiao>(pageNo, pageSize);
		 QueryWrapper<Zhibiaobiao> queryWrapper1 = new QueryWrapper<>();
		 queryWrapper1.eq("zerenbumen",departId);
		 IPage<Zhibiaobiao> pageList1 = zhibiaobiaoService.page(page1, queryWrapper1);
		 IPage<ZhibiaobiaoDto> dtoList = new Page<>();
		 List<Zhibiaobiao> list1 = pageList1.getRecords();
		 List<ZhibiaobiaoDto> dto = new ArrayList<>();
		 for(int i=0;i<list1.size();i++){
			 ZhibiaobiaoDto zhibiaobiaoDto = new ZhibiaobiaoDto();
			 BeanUtils.copyProperties(list1.get(i),zhibiaobiaoDto);
			 zhibiaobiaoDto.setZhuguanpeihe("我主管的");
			 dto.add(zhibiaobiaoDto);
		 }

		 //根据获取的部门id，去接收表根据配合部门查出自己配合的项目，并筛选出状态为“已接受”的，再根据指标id去指标表获取对应记录展示出来，并给主管/配合字段赋“我配合的”字段
		 Page<Jieshouzhibiaodaibanbiao> page2 = new Page<Jieshouzhibiaodaibanbiao>(pageNo, pageSize);
		 QueryWrapper<Jieshouzhibiaodaibanbiao> queryWrapper2 = new QueryWrapper<>();
		 queryWrapper2.and(qw -> qw.eq("peihebumen",departId).eq("zhuangtai","已接收"));
		 IPage<Jieshouzhibiaodaibanbiao> pageList2 = jieshouzhibiaodaibanbiaoService.page(page2, queryWrapper2);

		 List<Jieshouzhibiaodaibanbiao> list2 = pageList2.getRecords();
		 for(int j=0;j<list2.size();j++){
			 ZhibiaobiaoDto zhibiaobiaoDto = new ZhibiaobiaoDto();
			 String zhibiaoid = list2.get(j).getZhibiaoid();
			 System.out.println("zhibiaoid:"+zhibiaoid);
			 QueryWrapper<Zhibiaobiao> queryWrapper3 = new QueryWrapper<>();
			 queryWrapper3.eq("id",zhibiaoid);
			 Zhibiaobiao zhibiao = zhibiaobiaoService.getById(zhibiaoid);
			 BeanUtils.copyProperties(zhibiao,zhibiaobiaoDto);
			 zhibiaobiaoDto.setZhuguanpeihe("我配合的");
			 dto.add(zhibiaobiaoDto);
		 }
		 dtoList.setRecords(dto);
		 return Result.OK(dtoList);
	 }


//	 @PostMapping(value="/liebiaoList")
//	 public Result<String> liebiaoList(){
//		 for(int i = 0;i<1000000000;i++){
//			 Zhibiaobiao zhibiaobiao = new Zhibiaobiao();
//			 // 生成一个随机UUID（V4版本）
//			 UUID uuid = UUID.randomUUID();
//			 // 转换为36位字符串（含连字符），格式如：xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
//			 String uuidStr = uuid.toString();
//			 zhibiaobiao.setId(uuidStr);
//			 zhibiaobiao.setZerenbumen("1970854176330739713");
//			 zhibiaobiao.setPeihebumen("1970854176330739713,1970854111029620737,");
//			 zhibiaobiao.setKoahezhibiao("utf8 与 utf8mb4 的区别：MySQL 中的 utf8 实际是 “utf8mb3”，仅支持 3 字节字符，而 utf8mb4 支持 4 字节字符（如部分 emoji、生僻字），推荐优先使用 utf8mb4。");
//			 zhibiaobiao.setGongzuoluoshijihua("1");
//			 zhibiaobiao.setQuanzhong(1.0);
//			 zhibiaobiao.setJibenmubiaozhi("1");
//			 zhibiaobiao.setJilimubiaozhi("2");
//			 zhibiaobiao.setZhibiaoyaoqiu("不，MySQL 中一行（数据行）");
//			 zhibiaobiao.setZhibiaoleixing("1");
//			 zhibiaobiaoService.save(zhibiaobiao);
//		 }
//		 return Result.OK("添加成功！");
//	 }
	
	/**
	 *   添加
	 *
	 * @param zhibiaobiao
	 * @return
	 */
	@AutoLog(value = "制定年度关键指标-添加")
	@Operation(summary="制定年度关键指标-添加")
	@RequiresPermissions("zhibiaobiao:x_zhibiaobiao:add")
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody Zhibiaobiao zhibiaobiao) {
		//部长id   1970852625298092033
		//通过部长id，只让部长执行添加操作
		//获取登录用户的角色id
		LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
		String userId = loginUser.getId();
		QueryWrapper<SysUserRole> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("user_id",userId);
		String roleId = sysUserRoleService.getOne(queryWrapper).getRoleId();
		System.out.println("角色id"+roleId);
		if(roleId.equals("1970852625298092033")){
			zhibiaobiao.setZerenbumen(loginUser.getDepartIds());
			zhibiaobiao.setJindu("0%");
			zhibiaobiaoService.save(zhibiaobiao);

			//首先new一个接受指标代办表的对象，用来接收数据
			//根据每一条指标表记录，把配合部门拆开，分别插入指标id，配合部门id，以及默认状态“待处理”
			String[] str = zhibiaobiao.getPeihebumen().split(",");
			List<Jieshouzhibiaodaibanbiao> list = new ArrayList<>();
			for(int i =0; i < str.length; i++){
				Jieshouzhibiaodaibanbiao js = new Jieshouzhibiaodaibanbiao();
				js.setZhibiaoid(zhibiaobiao.getId());
				js.setPeihebumen(str[i]);
				js.setZhuangtai("待处理");
				list.add(js);
			}
			//将保存数据的对象存入list中，再批量保存进数据库
			jieshouzhibiaodaibanbiaoService.saveOrUpdateBatch(list);

			return Result.OK("添加成功！");
		}else{
			return Result.error("您没有权限执行此操作！");
		}
	}

//	@PostMapping(value = "/addJieshou")
//	public Result<String> addJieshou(@RequestBody Zhibiaobiao zhibiaobiao){
//		//首先new一个接受指标代办表的对象，用来接收数据
//		//根据每一条指标表记录，把配合部门拆开，分别插入指标id，配合部门id，以及默认状态“待处理”
//		String[] str = zhibiaobiao.getPeihebumen().split(",");
//		List<Jieshouzhibiaodaibanbiao> list = new ArrayList<>();
//		for(int i =0; i < str.length; i++){
//			Jieshouzhibiaodaibanbiao js = new Jieshouzhibiaodaibanbiao();
//			js.setZhibiaoid(zhibiaobiao.getId());
//			js.setPeihebumen(str[i]);
//			js.setZhuangtai("待处理");
//			list.add(js);
//		}
//		//将保存数据的对象存入list中，再批量保存进数据库
//		jieshouzhibiaodaibanbiaoService.saveOrUpdateBatch(list);
//		return Result.OK("添加成功！");
//	}

	/**
	 *  配合部门
	 */
	 @AutoLog(value = "制定年度关键指标-配合部门")
	 @Operation(summary="制定年度关键指标-配合部门")
//	 @RequiresPermissions("depart:sys_depart:peihe")
	 @GetMapping(value = "/peihe")
	 public Result<List<Map<String,Object>>> peiheList() {
		 QueryWrapper<SysDepart> queryWrapper = new QueryWrapper();
		 queryWrapper.like("depart_name","部");
		 List<SysDepart> departList = sysDepartMapper.selectList(queryWrapper);
		 List<Map<String,Object>> list = new ArrayList<>();
		 for(int i = 0; i < departList.size(); i++){
			list.add(Map.of("id",departList.get(i).getId(),"departName",departList.get(i).getDepartName()));
		 }
		 return Result.OK(list);
	 }

	 @AutoLog(value = "制定年度关键指标-配合部门")
	 @Operation(summary="制定年度关键指标-配合部门")
	 @PostMapping(value = "/zhibiaoleixing")
	 public Result<List> zhibiaoleixingList() {
		 QueryWrapper<Zhibiaoleixing> queryWrapper = new QueryWrapper();
		 queryWrapper.select("id","mingcheng");
		 List<Zhibiaoleixing> zhibiaoleixingList = zhibiaoleixingMapper.selectList(queryWrapper);
		return Result.OK(zhibiaoleixingList);
	 }
	/**
	 *  编辑
	 *
	 * @param zhibiaobiao
	 * @return
	 */
	@AutoLog(value = "制定年度关键指标-编辑")
	@Operation(summary="制定年度关键指标-编辑")
	@RequiresPermissions("zhibiaobiao:x_zhibiaobiao:edit")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody Zhibiaobiao zhibiaobiao) {
		zhibiaobiaoService.updateById(zhibiaobiao);
		return Result.OK("编辑成功!");
	}
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "制定年度关键指标-通过id删除")
	@Operation(summary="制定年度关键指标-通过id删除")
	@RequiresPermissions("zhibiaobiao:x_zhibiaobiao:delete")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		zhibiaobiaoService.removeById(id);
		return Result.OK("删除成功!");
	}
	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "制定年度关键指标-批量删除")
	@Operation(summary="制定年度关键指标-批量删除")
	@RequiresPermissions("zhibiaobiao:x_zhibiaobiao:deleteBatch")
	@DeleteMapping(value = "/deleteBatch")
	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.zhibiaobiaoService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "制定年度关键指标-通过id查询")
	@Operation(summary="制定年度关键指标-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<Zhibiaobiao> queryById(@RequestParam(name="id",required=true) String id) {

		Zhibiaobiao zhibiaobiao = zhibiaobiaoService.getById(id);
		if(zhibiaobiao==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(zhibiaobiao);
	}

    /**
    * 导出excel
    *
    * @param request
    * @param zhibiaobiao
    */
    @RequiresPermissions("zhibiaobiao:x_zhibiaobiao:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, Zhibiaobiao zhibiaobiao) {
        return super.exportXls(request, zhibiaobiao, Zhibiaobiao.class, "制定年度关键指标");
    }

    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
    @RequiresPermissions("zhibiaobiao:x_zhibiaobiao:importExcel")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, Zhibiaobiao.class);
    }



	//导入表格
	 @RequestMapping(value="daoruExcel")
	 public Result<List> daoruExcel(String filePath){
		filePath="D:\\devwork\\excel\\指标.xlsx";
		List<Zhibiaobiao> dataList = new ArrayList<>();

		try(final FileInputStream fis = new FileInputStream(new File(filePath));

			Workbook workbook = WorkbookFactory.create(fis)){

			//遍历所有工作表
			for(Sheet sheet: workbook){
				//遍历行
				Iterator<Row> rowIterator = sheet.rowIterator();
				int index = 0;
				while(rowIterator.hasNext()){
					index++;

					Row row = rowIterator.next();


					for(int i = 0; i < 13; i++){
						Cell cell1;
						cell1=row.getCell(i);
						if(cell1==null){
							cell1 = row.createCell(i);
							if(i == 0){
								cell1.setCellValue("无");
							} else if (i == 1) {
								cell1.setCellValue("无");
							} else if (i == 2) {
								cell1.setCellValue(0.0);
							}else if (i == 3 ){
								cell1.setCellValue("无");
							} else if (i == 4 ){
								cell1.setCellValue("无");
							}else if (i == 5) {
								cell1.setCellValue("无");
							}else if (i == 6) {
								cell1.setCellValue("无");
							}else if (i == 7) {
								cell1.setCellValue("无");
							}else if (i == 8) {
								cell1.setCellValue("无");
							}else if (i == 9) {
								cell1.setCellValue("无");
							} else if (i == 10) {
								cell1.setCellValue("无");
							}else if (i == 11) {
								cell1.setCellValue("无");
							} else if (i == 12) {
								cell1.setCellValue("无");
							}
						}
					}

					List<String> rowData = new ArrayList<>();

					if(index>1){
						//遍历单元格
						Iterator<Cell> cellIterator = row.cellIterator();

						while(cellIterator.hasNext()){
							Cell cell = cellIterator.next();
							//根据单元格类型获取值
							String cellValue =getCellValue(cell);
							rowData.add(cellValue);

						}
						Zhibiaobiao zhibiaobiao = new Zhibiaobiao();

							String zhibiao1 = rowData.get(0);
							QueryWrapper<Zhibiaoleixing> queryWrapper = new QueryWrapper<>();
							queryWrapper.eq("id",zhibiao1);
							Zhibiaoleixing zhibiaoleixing = zhibiaoleixingMapper.selectOne(queryWrapper);
							if(zhibiaoleixing != null){
								zhibiaobiao.setZhibiaoleixing(zhibiaoleixing.getId());
							}else{
								zhibiaobiao.setZhibiaoleixing(rowData.get(0));
							}

							zhibiaobiao.setKaohezhibiao(rowData.get(1));
							zhibiaobiao.setQuanzhong(Double.parseDouble(rowData.get(2)));
							zhibiaobiao.setZhibiaodingyijigongshi(rowData.get(3));
							zhibiaobiao.setPingjiaxize(rowData.get(4));

							String zhibiao5 = rowData.get(5);
							QueryWrapper<SysDepart>	queryWrapper1 = new QueryWrapper<>();
							queryWrapper1.eq("depart_name",zhibiao5);
							SysDepart sysDepart = sysDepartMapper.selectOne(queryWrapper1);
							if(sysDepart != null){
								zhibiaobiao.setZerenbumen(sysDepart.getId());
							}else{
								zhibiaobiao.setZerenbumen(rowData.get(5));
							}


							zhibiaobiao.setJibenmubiaozhi(rowData.get(6));
							zhibiaobiao.setJilimubiaozhi(rowData.get(7));
							zhibiaobiao.setGongzuoluoshijihua(rowData.get(8));
							zhibiaobiao.setZhibiaoyaoqiu(rowData.get(9));
							zhibiaobiao.setJutiluoshiqingkuang(rowData.get(10));

							String zhibiao11 = rowData.get(11);
							if(zhibiao11.equals("无")){
								zhibiaobiao.setPeihebumen(rowData.get(11));
							}else{
								String[] parts = zhibiao11.split("，");
								String peiheName = "";
								for(int i =0;i<parts.length;i++){
									String peihe = parts[i];
									QueryWrapper<SysDepart> queryWrapper2 = new QueryWrapper<>();
									queryWrapper2.eq("depart_name",peihe);
									SysDepart sysDepart1 = sysDepartMapper.selectOne(queryWrapper2);
									String name = sysDepart1.getId();
									peiheName = peiheName + name + ",";
								}
								zhibiaobiao.setPeihebumen(peiheName);
							}

							zhibiaobiao.setJindu(rowData.get(12));

						zhibiaobiaoService.save(zhibiaobiao);
						dataList.add(zhibiaobiao);
					}

				}

			}
		}catch (IOException e){
			e.printStackTrace();
		}
		return Result.ok(dataList);
	 }
	private static String getCellValue(Cell cell){
		if(cell == null){
			return "";
		}

		String value = "";
		switch(cell.getCellType()){
			case STRING:
				value = cell.getStringCellValue();
				break;
			case NUMERIC:
				//判断是否为日期类型
				if(DateUtil.isCellDateFormatted(cell)){
					value = cell.getDateCellValue().toString();
				}else{
					//数字类型，避免科学计数
					value= String.valueOf(cell.getNumericCellValue());
				}
				break;
			case BOOLEAN:
				value = String.valueOf(cell.getBooleanCellValue());
				break;
			case FORMULA:
				value = cell.getCellFormula();
				break;
			default:
				break;
		}
		return value;
	}



/*	private   class Calculator {
		 public  void main(String[] args) {
			 // 1. 定义两个整数
			 int a = 10;
			 int b = 3;

			 // 2. 计算和
			 int sum = a + b;
			 System.out.println(a + " + " + b + " = " + sum);

			 // 3. 计算差
			 int sub = a - b;
			 System.out.println(a + " - " + b + " = " + sub);

			 // 4. 计算积
			 int mul = a * b;
			 System.out.println(a + " * " + b + " = " + mul);

			 double i = div(a,b);
			 System.out.println("结果为："+i);
			 // 5. 计算商（处理除数为0的情况）
//			 if (b == 0) {
//				 System.out.println("除数不能为0");
//			 } else {
//				 int div = a / b;
//				 System.out.println(a + " / " + b + " = " + div);
//			 }



			 // 如果需要再计算一组数（比如 8 和 2），必须重复写上述所有代码
			 int c = 8;
			 int d = 2;

			 int sum2 = c + d;
			 System.out.println(c + " + " + d + " = " + sum2);

			 int sub2 = c - d;
			 System.out.println(c + " - " + d + " = " + sub2);

			 int mul2 = c * d;
			 System.out.println(c + " * " + d + " = " + mul2);

			 if (d == 0) {
				 System.out.println("除数不能为0");
			 } else {
				 int div2 = c / d;
				 System.out.println(c + " / " + d + " = " + div2);
			 }
		 }
		 public String div(int a,int b){
			 if(b==0){
				 System.out.println("除数不能为0");
				 return "0";
			 }else{
				 double i = a/b;
				 String str = String.valueOf(i);
				 return str;
			 }
		 }
	 }*/





 }
